package com.leetcode.partition5;

/**
 * @author `RKC`
 * @date 2021/10/7 9:47
 */
public class LC434字符串中的单词数 {

    public static int countSegments(String s) {
        if (s.length() == 0) return 0;
        String t = "";
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == ' ') continue;
            t = s.substring(i);
            break;
        }
        if (s.charAt(0) == ' ' && t.length() > 0) {
            return t.split(" +").length;
        } else if (s.charAt(0) == ' ' && t.length() == 0) {
            return 0;
        }
        return s.split(" +").length;
    }

    public static void main(String[] args) {
//        String s = "Hello, my name is John";
        String s = "          ";
//        String s = "love  live! mu'sic forever";
//        String s = ", , , ,        a, eaefa";
        System.out.println(countSegments(s));
//        System.out.println(Arrays.toString(s.split(" +")));
//        System.out.println(s.split(" +").length);
    }
}
